<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <title>使用 setCookie() 函数</title>
</head>
<body>
<script>
    function setCookie(name, value, expries, path) {
        value = decodeURI(value);
        if (!expries) {
            var now = new Date();
            now.setMonth(now.getMonth() + 6);
            expries = now.toUTCString();
        }
        if (path) {
            path = ';path=' + path;
        }
        document.cookie = name + '=' + value + ';expries=' + expries + path;
    }

    setCookie('Name', 'Bob');
    setCookie('Age', '101');
    setCookie('FirstVisit', '10 May 2007');
    alert(document.cookie);
</script>
</body>
</html>